package com.life.notes.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.life.notes.config.interceptor.BaseContextHandler;
import com.life.notes.dao.PhoneMapper;
import com.life.notes.dto.PhoneQueryPara;
import com.life.notes.model.PhoneEntity;
import com.life.notes.service.PhoneService;
import org.springframework.stereotype.Service;

/**
 * @Description 手机号业务实现
 * @Author Sans
 * @CreateTime 2019/9/14 15:57
 */
@Service("phoneService")
public class PhoneServiceImpl extends ServiceImpl<PhoneMapper, PhoneEntity> implements PhoneService {

    @Override
    public IPage<PhoneEntity> listPage(PhoneQueryPara filter) {
        Page<PhoneEntity> page = new Page<>(filter.getPage(),filter.getLimit());
        return this.baseMapper.selectPhones(page, filter);
    }

    @Override
    public Integer savePhone(PhoneEntity para) {
        para.setUserId(BaseContextHandler.getUserId());
        if (para.getId()!=null) {
            this.baseMapper.updateById(para);
        } else {
            this.baseMapper.insert(para);
        }
        return para.getId();
    }
}